import { director, log } from 'cc';
import { System } from 'cc';
import { color } from 'cc';
import { _decorator, Component, Node } from 'cc';
import { BaseManager } from '../libs/rxjs/cc3/BaseManager';
const { ccclass, property } = _decorator;

@ccclass('TimeManager')
export class TimeManager extends BaseManager {

    public static instance: TimeManager;
    static ID = 'time_system';
    get logColorOverride() { return color().fromHEX('#EEDDDD') };

    static registerSystem() {
        director.unregisterSystem(director.getSystem(TimeManager.ID));
        director.registerSystem(TimeManager.ID, timem, System.Priority.MEDIUM);
    }

    onInitManager() {
        this.log('onInitManager', this.timestamp);
    }

    getCurrentDate(): Date {
        return new Date();
    }

    now(): number {
        return Date.now();
    }

    getNowYYMMDD() {
        const now = new Date();
        const year = now.getFullYear().toString().slice(-2);
        const month = (now.getMonth() + 1).toString().padStart(2, '0');
        const day = now.getDate().toString().padStart(2, '0');
        const result = year + month + day;
        return result;
    }
}

globalThis.TimeManager = TimeManager;

export const timem = TimeManager.instance = new TimeManager();